package com.saltlux.tdd.algorithm;

import junit.framework.Assert;

import org.junit.Test;

public class IndexFinderTester {
	@Test
	public void testFindingFirstGreaterIndex() {
		String[] fixture = new String[] { "a", "c", "d" };
		String newString = "b";
		StringValueComparator comparator = new StringValueComparator();

		IndexFinder finder = new IndexFinder();
		int result = finder.findFirstGreater(fixture, newString, comparator);

		Assert.assertEquals(1, result);
	}

	@Test
	public void testFindingFirstLongerIndex() {
		String[] fixture = new String[] { "a1", "c123", "d2" };
		String newString = "b12";
		StringLengthComparator comparator = new StringLengthComparator();

		IndexFinder finder = new IndexFinder();
		int result = finder.findFirstGreater(fixture, newString, comparator);

		Assert.assertEquals(1, result);
	}

	@Test
	public void testFindingCenterIndex() {
		String[] evenFixture = new String[] { "a1", "c123", "d2", "elf" };
		String[] oddFixture = new String[] { "a1", "c123", "d2" };

		IndexFinder finder = new IndexFinder();
		Assert.assertEquals(2, finder.findCenter(evenFixture, 0, 3));
		Assert.assertEquals(3, finder.findCenter(evenFixture, 2, 3));
		Assert.assertEquals(1, finder.findCenter(oddFixture, 0, 2));
		Assert.assertEquals(1, finder.findCenter(oddFixture, 0, 7));
	}
}
